/* EIX - IPC system
 * Copyright (C) 2008-2011 Jorge Luis Zapata
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.
 * If not, see <http://www.gnu.org/licenses/>.
 */
#include "Eix.h"
#include "eix_private.h"
/*============================================================================*
 *                                  Local                                     *
 *============================================================================*/
static int _init = 0;
/*============================================================================*
 *                                 Global                                     *
 *============================================================================*/
int eix_log;
/*============================================================================*
 *                                   API                                      *
 *============================================================================*/
/**
 * Initialize the Eix library. You must call this function before any
 * other call to an Eix function.
 */
EAPI void eix_init(void)
{
	if (_init++) return;

	eina_init();
	eix_log = eina_log_domain_register("eix", NULL);
	ender_init();
	eix_message_init();
}

/**
 * Shutdowns the Eix library. Once you have finished using Eix
 * call this function to deinitialize everything
 */
EAPI void eix_shutdown(void)
{
	if (_init == 1)
	{
		eix_message_shutdown();
		ender_shutdown();
		eina_log_domain_unregister(eix_log);
		eina_shutdown();
	}
	_init--;
}

EAPI void eix_error_set(Eix_Error *e,
		Eix_Error_Code code, const char *str)
{
	if (!e) return;
	if (code == EIX_ERR_NONE)
	{
		WRN("Use an error code, not 'EIX_ERR_NONE'");
		return;
	}

	e->code = code;
	if (str) e->msg = strdup(str);
}
